import React,{ useState,useEffect } from 'react'
import './App.css'
import { AuthContext,authInitialState, authReducer } from './contexts/authContext'
import Header from './components/Header'
import AddSong from './components/AddSong'


function App() {
  // useReducer 是比 usestate 更严格的状态管理
  const [state,dispatch]=React.useReducer(authReducer,authInitialState)
  useEffect(()=>{
    setTimeout(() => {
      dispatch({type: "LOGIN", payload:{user:{name:'yzx',age:18}, token:{t:'11111111'}}})
    }, 2000);
  },[])
  return (
    <AuthContext.Provider value={{
      state,
      dispatch
    }}>
      <Header />
      {state.isAuthenticated &&<AddSong />}
    </AuthContext.Provider>
  )
}

export default App
